package org.linlinjava.litemall.web.controller;

import io.swagger.annotations.Api;
import org.linlinjava.litemall.web.annotation.LogAnno;
import org.linlinjava.litemall.web.annotation.LoginShop;
import org.linlinjava.litemall.web.dto.WebPointExchangeOrderDTO;
import org.linlinjava.litemall.web.service.WebPointExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 点交换控制器
 *
 * @author yliyun
 * @date 2022/09/14
 */
@Api(tags = "积分兑换商品API")
@RestController
@RequestMapping("/web/pointExchange")
@Validated
public class WebPointExchangeController {

    /**
     * wx点交换服务
     */
    @Autowired
    private WebPointExchangeService webPointExchangeService;

    /**
     * 列出所有点交流
     * 查询所有的积分兑换
     *
     * @return {@link Object}
     */
    @GetMapping("listAllPointExchange")
    @LogAnno
    public Object listAllPointExchange(){
        return webPointExchangeService.listAllPointExchange();
    }


    /**
     * 类别点交流
     * 查出指定积分兑换的商品三级分类
     *
     * @param pointExchangeId 点交易id
     * @return {@link Object}
     */
    @GetMapping("categoryPointExchange")
    @LogAnno
    public Object categoryPointExchange(Integer pointExchangeId){
       return  webPointExchangeService.categoryPointExchange(pointExchangeId);
    }

    /**
     * 点交易类别id
     * 通过三级分类查询可兑换商品
     *
     * @param categoryId      类别id
     * @param pointExchangeId 点交易id
     * @param shopId          商店id
     * @return {@link Object}
     */
    @GetMapping("pointExchangeByCategoryId")
    @LogAnno
    public Object pointExchangeByCategoryId(@RequestParam Integer categoryId,
                                            @RequestParam Integer pointExchangeId,
                                            @LoginShop Integer shopId){

        return webPointExchangeService.pointExchangeByCategoryId(categoryId,pointExchangeId,shopId);
    }

    /**
     * 良好细节和交换
     * 查询商品信息，规格，属性，添加辅料
     *
     * @param goodsId 商品id
     * @return {@link Object}
     */
    @GetMapping("goodDetailAndExchange")
    @LogAnno
    public Object goodDetailAndExchange(@RequestParam Integer goodsId,
                                        @RequestParam("pointExchangeId") Integer pointExchangeId){
        return webPointExchangeService.goodDetailAndExchange(goodsId,pointExchangeId);
    }

    /**
     * 积分兑换下单
     *
     * @param dto    dto
     * @return {@link Object}
     */
    @PostMapping("orderByPoint")
    @LogAnno
    @Transactional
    public Object orderByPoint(@RequestBody WebPointExchangeOrderDTO dto,@LoginShop Integer shopId){
        return webPointExchangeService.orderByPoint(dto,shopId);
    }
}
